#include<iostream>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdio.h>
#include<unistd.h>
#include<string.h>

using namespace std;

int main()
{
    //打开文件
    //FILE* fd = fopen("zjx.txt","w");
    //if(fd==NULL)
    //{
    //    perror("fopen fail");
    //    return 1;
    //}
    int fd = open("zjx.txt",O_WRONLY|O_CREAT|O_TRUNC,0666);
    if(fd<0)
    {
        perror("open fail");
        return 1;
    }

    //操作文件
    //const char* str ="linux so easy!\n";
    const char* str ="i love linux\n";
    //fwrite(str , strlen(str),1,fd);
    write(fd,str,strlen(str));

    //关闭文件
    //fclose(fd);
    //fd = NULL;
    close(fd);
    return 0;
}
